{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5edbcc0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_id = [1001, 1002, 1003, 1004, 1005, 1001, 1006, 1007, 1001]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "d39de0bf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "0\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "# 用for和if循环取出所有位置10001的index\n",
    "for i in stu_id:\n",
    "    # 循环遍历stu_id的所有内容\n",
    "    if i == 1001:\n",
    "        # 判断如果元素为1001的时候,怎么取出索引值呢？\n",
    "        print(stu_id.index(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "072122d8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      " \n",
      " \n",
      " \n",
      "[1002, 1003, 1004, 1005, 1006, 1007]\n"
     ]
    }
   ],
   "source": [
    "# 一般方法\n",
    "for i in stu_id:\n",
    "    if i == 1001:\n",
    "        stu_id.remove(1001)\n",
    "    else:\n",
    "        print(\" \")\n",
    "print(stu_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "479e274c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1001\n",
      "5 1001\n",
      "8 1001\n",
      "我们想要删除pop()的值： [0, 5, 8]\n"
     ]
    }
   ],
   "source": [
    "# 枚举:因为list其实不仅有values值，还有index索引，但for循环主要循环遍历其值，不遍历索引\n",
    "# 因此，有了枚举的方法，同时遍历两者\n",
    "# enumerate()\n",
    "stu_id = [1001, 1002, 1003, 1004, 1005, 1001, 1006, 1007, 1001]\n",
    "pop_values_list = []  # append方法经常用于新建列表\n",
    "for index,item in enumerate(stu_id):\n",
    "    # print(index,item)\n",
    "    if item == 1001:\n",
    "        print(index,item)\n",
    "        pop_values_list.append(index)\n",
    "print(\"我们想要删除pop()的值：\", pop_values_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a8a2d04",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
